<?php  
    session_start();
    require_once('userlevel.php'); //Require/include the permissions file
    require_once('template.php'); //Require/include the template file
    require_once('functions.php'); //Require/include the functions file
    require_once('db.php'); //Require/include the file with the database connection information
     
    if (!$_SESSION['user_loggedin']) {
        die ("Not logged in... <script>document.location.href='login.php'</script>");
    } elseif (!($_SESSION['userlevel'] >= $userlevel['main'])) {
        die (errorpage ("Your user level is not high enough to use this feature!", 'Tracked files'));
    } else {
        //Connect to to the database using values provided by db.php
        $db = new my_db;
         
        template_headtag('Track');
        template_header();
        template_left();
        echo "<div class='pageheadertext'>All Tracked Files</div><br/>";
        
        $db->query("SELECT DISTINCT filepath FROM trackedfiles ORDER BY filepath");
        if ($db->nf() > 0) {
            echo "<div align='left'><table class='table'>";
            while ($db->next_record()) {
                $dir = strip_tags($db->f('filepath'));
                if ($rowstyle == 'oddrow') {
                    $rowstyle = 'evenrow';
                } else {
                    $rowstyle = 'oddrow';
                }
                echo "<tr class='$rowstyle'>";
                echo "<td align='left' width='100%'>";
                echo "<img src='images/tables/folder.png' />&nbsp;&nbsp;<a href='listfiles.php?dir=".urlencode($dir)."'>$dir</a>&nbsp;";
                echo "</td>";
                if ($_SESSION['userlevel'] >= $userlevel['stoptrackingfile']) {
                    echo "<td>";
                    echo "<a href='stoptrackingdir.php?dir=".urlencode($dir)."' title='Stop tracking directory'><img src='images/tables/stop.png' width='16' height='16' border='0' alt='Stop tracking directory' /></a>";
                    echo "</td>";
                }
                echo "</tr>";
            }
            echo "</table></div>";
        } else {
            echo "<div align='center'><table class='table' style='width:400px;'>";
            echo "<tr><td><br />No tracked files found!<br /><br />Track a <a href='addfile.php'>file</a> or a <a href='adddir.php'>directory</a><br /><br /><br /></td></tr>";
            echo "</table></div>"; 

        }
         
        template_footer();
    }
?>
